$(function () {
    var eid = GetQueryString("eid");
    var meetNum = GetQueryString("meetNum");
    var type = GetQueryString("type");
    var sel = $.Params.create();
    sel.ajax("get", getAdminIP() + "pfMembers/" + eid, function (data) {
        if (data.success) {
            var val = data.result;
            $("#headUrl").attr("src", getIP() + "data/expertImg/" + val.headImg);
            $("#name").val(val.name);
            $("#tel").val(val.tel);
            $("#hospitalName").val(val.hospitalName);
        } else {
            alert(data.msg);
        }
    })
    $("#headImg").on("change", function (e) {
        var src, url = window.URL || window.webkitURL || window.mozURL, files = e.target.files;
        // for (var i = 0, len = files.length; i < len; ++i) {
        var file = files[0];
        if (url) {
            src = url.createObjectURL(file);
        } else {
            src = e.target.result[0];
        }

        $("#headUrl").attr('src', src);
        // }
    });


    $("#addData").on("click", function () {
        var name = $("#name").val();
        var tel = $("#tel").val();
        var hospitalName = $("#hospitalName").val();
        if (name == "") {
            alert("姓名不能为空！");
            return false;
        }
        if (!(valPhone(tel))) {
            alert("手机格式不正确！");
            return false;
        }
        if (hospitalName == "") {
            alert("医院不能为空！");
            return false;
        }
        $("#addForm").attr("action", getAdminIP() + "pfMembers/updateMember/" + meetNum + "/" + type + "/" + eid);
        $("#addForm").submit();
        // var addSel = $.Params.create();
        // addSel.addParams("name", name);
        // addSel.addParams("tel", tel);
        // addSel.addParams("hospitalName", hospitalName);
        // addSel.ajax("put", getAdminIP() + "pfMembers/" + eid, function (data) {
        //     if (data.success) {
        //         if (type == "1") {
        //             window.location.href = "pfMemberJudgeList.html?meetNum=" + meetNum + "&type=" + type;
        //         } else if (type == "2") {
        //             window.location.href = "pfMemberPlayerList.html?meetNum=" + meetNum + "&type=" + type;
        //         }
        //     } else {
        //         alert(data.msg);
        //     }
        // })
    })
    $("#cancelAdd").on("click", function () {
        history.go(-1);
    })
})